﻿<UserControl x:Class="TanmiaGrp.GeneralLedger.WinApp.Scenarios.JournalBrowserView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:loc="clr-namespace:TanmiaGrp.GeneralLedger.WinApp"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:Scenarios="clr-namespace:TanmiaGrp.GeneralLedger.WinApp.Scenarios"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mui="http://firstfloorsoftware.com/ModernUI"
             mc:Ignorable="d"
             d:DesignHeight="300"
             d:DesignWidth="600"
             FlowDirection="RightToLeft"
             Background="Transparent"
             PreviewMouseDown="UserControl_PreviewMouseDown">
    <UserControl.Resources>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        <loc:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
    </UserControl.Resources>

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <Grid Name="searchBar" Grid.Column="0" Width="0">
            <Grid.Resources>
                <Style TargetType="{x:Type mui:ModernButton}">
                    <Setter Property="Width" Value="32" />
                    <Setter Property="Height" Value="32" />
                    <Setter Property="EllipseDiameter" Value="30" />
                    <Setter Property="Foreground" Value="#FFA1A1A1" />
                    <Setter Property="Margin" Value="2,0,0,0" />
                    <Setter Property="IconWidth" Value="12" />
                    <Setter Property="IconHeight" Value="12" />
                    <Setter Property="Background" Value="White" />
                    <Setter Property="BorderBrush" Value="#919191" />
                    <Setter Property="EllipseStrokeThickness" Value="2" />
                </Style>
            </Grid.Resources>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <DockPanel Grid.Row="0" Height="46">
                <TextBlock Text="البحث" Foreground="#FF6699C9" FontSize="22" VerticalAlignment="Center" Margin="4,0" />

                <!-- Close SearchPanel Button -->
                <mui:ModernButton ToolTip="خلف" FlowDirection="LeftToRight" IconData="{StaticResource Back}" HorizontalAlignment="Right" Margin="0,0,2,0">
                    <mui:ModernButton.Triggers>
                        <EventTrigger RoutedEvent="Button.Click">
                            <BeginStoryboard>
                                <Storyboard>
                                    <!-- Contract width of SearchBar -->
                                    <DoubleAnimation Storyboard.TargetName="searchBar"
                                                 Storyboard.TargetProperty="Width"
                                                 To="0"
                                                 Duration="0:0:.4" />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </mui:ModernButton.Triggers>
                </mui:ModernButton>
            </DockPanel>

            <Grid Grid.Row="1">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <TextBox Name="txtSearch" 
                         Grid.Row="0"
                         Height="30" 
                         VerticalContentAlignment="Top" 
                         FontSize="16" 
                         Text="{Binding Path=SearchSpecification.InteractiveSearch, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Margin="4,2,4,0" />

                <CheckBox Grid.Row="1" 
                          Height="32" 
                          Foreground="Gray" 
                          Content="اظهار المجموعات الموقفة" 
                          Margin="4,0" 
                          VerticalAlignment="Top" 
                          IsChecked="{Binding Path=SearchSpecification.ShowIsDisabled, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>
            </Grid>

            <DockPanel Grid.Row="2" Height="46">
                <mui:ModernButton ToolTip="تحديث البيانات"
                                  IconData="{StaticResource Refresh}"
                                  HorizontalAlignment="Right"
                                  Margin="0,0,2,0"
                                  Command="{Binding Path=RefreshCommand}" 
                                  CommandParameter="{x:Static loc:NavigationMoveEnum.KeepCurrent}"/>
            </DockPanel>

            <!-- separator between panels -->
            <Border Grid.Row="0" Grid.RowSpan="2" Grid.Column="1" Width="1" Margin="2,0">
                <Border.Background>
                    <LinearGradientBrush StartPoint=".5,0" EndPoint=".5,1">
                        <GradientStop Color="#FFDADADA" Offset="0.0" />
                        <GradientStop Color="#919191" Offset=".8" />
                        <GradientStop Color="#919191" Offset=".2" />
                        <GradientStop Color="#FFE4E4E4" Offset="1.0" />
                    </LinearGradientBrush>
                </Border.Background>
                <Border.Effect>
                    <DropShadowEffect ShadowDepth="0" Direction="1" Opacity="0.395" Color="#FF919191"  />
                </Border.Effect>
            </Border>
        </Grid>

        <Grid Grid.Column="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="2" />
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <DockPanel Grid.Row="0" Height="46">
                <DockPanel.Resources>
                    <Style TargetType="{x:Type mui:ModernButton}">
                        <Setter Property="Width" Value="32" />
                        <Setter Property="Height" Value="32" />
                        <Setter Property="EllipseDiameter" Value="30" />
                        <Setter Property="Margin" Value="2,0,0,0" />
                        <Setter Property="IconWidth" Value="12" />
                        <Setter Property="IconHeight" Value="12" />
                        <Setter Property="Background" Value="White" />
                        <Setter Property="Foreground" Value="#7f7f7f" />
                        <Setter Property="BorderBrush" Value="#c9c9c9" />
                        <Setter Property="EllipseStrokeThickness" Value="2" />
                    </Style>
                </DockPanel.Resources>
                <Scenarios:WindowBar x:Name="windowBar" PopouClicked="OnPopout" />
                <mui:ModernButton ToolTip="بحث" 
                                  IconData="{StaticResource Search}">
                    <mui:ModernButton.Triggers>
                        <EventTrigger RoutedEvent="Button.Click">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="searchBar" 
                                                     Storyboard.TargetProperty="Width"
                                                     To="200"
                                                     Duration="0:0:.6" AccelerationRatio="1" />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </mui:ModernButton.Triggers>
                </mui:ModernButton>

                <TextBlock DockPanel.Dock="Left" 
                           Text="اليومية" 
                           Style="{StaticResource CaptionStyle}" />
                <Scenarios:AddBar HorizontalAlignment="Right" DockPanel.Dock="Right" />

                <Scenarios:SelectionModificationBar DockPanel.Dock="Right" 
                                                    HorizontalAlignment="Right" 
                                                    Visibility="{Binding ElementName=dbAccounts, Path=SelectedItem, Converter={StaticResource NullToVisibilityConverter}}" />

                <mui:ModernButton DockPanel.Dock="Right"
                                  HorizontalAlignment="Right"
                                  ToolTip="{Binding Path=PostText, UpdateSourceTrigger=PropertyChanged}"
                                  IconData="{StaticResource Post}" 
                                  Visibility="{Binding ElementName=dbAccounts, Path=SelectedItem, Converter={StaticResource NullToVisibilityConverter}}" 
                                  Command="{Binding Path=PostCommand}" />
            </DockPanel>

            <ProgressBar Grid.Row="1" 
                         Minimum="0" 
                         Maximum="1" 
                         Height="2" 
                         IsIndeterminate="True" 
                         VerticalAlignment="Center" 
                         HorizontalAlignment="Stretch" 
                         Visibility="{Binding Path=EntitiesTask.IsNotCompleted, Converter={StaticResource BooleanToVisibilityConverter}}"/>
            
            <DataGrid Grid.Row="2" 
                      Name="dbAccounts"
                      ItemsSource="{Binding Path=EntitiesTask.Result.Entities}"
                      CanUserAddRows="False"
                      CanUserDeleteRows="False"
                      CanUserResizeRows="False"
                      IsSynchronizedWithCurrentItem="True"
                      FontFamily="Tahoma"
                      AutoGenerateColumns="False">

                <DataGrid.ItemContainerStyle>
                    <Style TargetType="DataGridRow">
                        <Setter Property="IsSelected"
                                Value="{Binding Path=IsSelected, Mode=TwoWay}" />
                    </Style>
                </DataGrid.ItemContainerStyle>
                <DataGrid.Columns>

                    <DataGridTextColumn Header="رقم اليومية"
                                        Binding="{Binding Path=JournalID}"
                                        IsReadOnly="True" />

                    <DataGridTextColumn Header="مجموع المدين"
                                        Binding="{Binding Path=TotalDebit}"
                                        IsReadOnly="True" />

                    <DataGridTextColumn Header="مجموع الدائن"
                                        Binding="{Binding Path=TotalCredit}"
                                        IsReadOnly="True" />

                    <DataGridTextColumn Header="الرصيد"
                                        Binding="{Binding Path=Balance}"
                                        IsReadOnly="True" />
                    
                    <DataGridTextColumn Header="تاريخ اليومية"
                                        Binding="{Binding Path=CreateDate}"
                                        IsReadOnly="True" />

                    <DataGridTextColumn Header="مرحل؟"
                                        Binding="{Binding Path=PostState}"
                                        IsReadOnly="True" />

                    <DataGridTextColumn Header="ملاحظات"
                                        Binding="{Binding Path=Notes}"
                                        IsReadOnly="True" />
                </DataGrid.Columns>
            </DataGrid>

            <Grid Grid.Row="3" Height="46">
                <Scenarios:PageNavigationBar HorizontalAlignment="Right" />
            </Grid>

            <!--<Label Content="Loading..."
                   VerticalContentAlignment="Center"
                   HorizontalContentAlignment="Center"
                   Background="White"
                   Opacity=".7"
                   Visibility="{Binding Path=EntitiesTask.IsNotCompleted, Converter={StaticResource BooleanToVisibilityConverter}}" />-->

            <!--<Label Content="{Binding Path=EntitiesTask.ErrorMessage}"
                   VerticalContentAlignment="Center"
                   HorizontalContentAlignment="Center"
                   Background="White"
                   Foreground="Red"
                   FontWeight="Bold"
                   Opacity=".5"
                   Visibility="{Binding Path=EntitiesTask.IsFaulted, Converter={StaticResource BooleanToVisibilityConverter}}" />-->
        </Grid>
    </Grid>

</UserControl>
